package com.korubo.web.contrller;

import cn.hutool.core.lang.UUID;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.korubo.kit.R;
import com.korubo.web.model.Menu;
import com.korubo.web.service.MenuService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * (tb_menu)表控制层
 *
 * @author xxxxx
 */
@RestController
@RequestMapping("/menu")
public class MenuController {
    /**
     * 服务对象
     */
    @Resource
    private MenuService menuService;

    //查询列表
    @PostMapping("list")
    public R listTree(@RequestBody(required = false) Menu menu) {
        return menuService.listTree(menu);
    }

    //添加
    @PostMapping("add")
    public R add(@RequestBody Menu menu) {
        menu.setId(UUID.fastUUID().toString());
        menuService.save(menu);
        return R.ok();
    }

    //修改
    @PostMapping("update")
    public R update(@RequestBody Menu menu) {
        return menuService.updateById(menu) ? R.ok() : R.fail();
    }

    //删除
    @PostMapping("delete")
    public R delete(@RequestBody Menu menu) {
        return menuService.removeById(menu.getId()) ? R.ok() : R.fail();
    }

    @PostMapping("findById")
    public R findById(@RequestBody Menu menu) {
        Menu byId = menuService.getById(menu.getId());
        return R.ok(byId);
    }
}
